package forcollege.xly.com.xian.net;


import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;

import io.reactivex.ObservableTransformer;

/**
 * Created by amos on 2018/6/7.
 */

public class JsonTransformer {

    public static <T> ObservableTransformer<String, T> transformer(Class<T> claz) {
        return upstream -> upstream.map(s -> {
            Gson gson = new Gson();

            T result;
            try {
                result = gson.fromJson(s, claz);
                return result;
            } catch (Exception e) {
                e.printStackTrace();
            }

            return null;
        });
    }

}
